package cn.anc.aonicardv.bean;

import android.os.Parcel;
import android.os.Parcelable;

import java.util.Calendar;

import androidx.annotation.NonNull;

/**
 * Created by yangdai on 2017/5/19.
 */

public class PhotoBean extends FileBean implements Parcelable, Comparable {

    private String date;
    private String name;
    private String resolution;
    private boolean isCheck;
    private int itemPosition;

    public PhotoBean() {
    }

    public PhotoBean(String date, String path, String name) {
        this(date, path, name, null, null);
    }



    public PhotoBean(String date, String path, String name, String resolution, String fileCreateTime) {
        this.date = date;
        this.path = path;
        this.name = name;
        this.resolution = resolution;
        this.fileCreateTime = fileCreateTime;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getResolution() {
        return resolution;
    }

    public void setResolution(String resolution) {
        this.resolution = resolution;
    }

    public boolean isCheck() {
        return isCheck;
    }

    public void setCheck(boolean check) {
        isCheck = check;
    }

    public int getItemPosition() {
        return itemPosition;
    }

    public void setItemPosition(int itemPosition) {
        this.itemPosition = itemPosition;
    }

    @Override
    public String toString() {
        return "PhotoBean{" +
                "date='" + date + '\'' +
                ", name='" + name + '\'' +
                ", resolution='" + resolution + '\'' +
                ", isCheck=" + isCheck +
                ", itemPosition=" + itemPosition +
                '}';
    }

    protected PhotoBean(Parcel in) {
        date = in.readString();
        name = in.readString();
        resolution = in.readString();
        isCheck = in.readByte() != 0;
        itemPosition = in.readInt();
    }

    public static final Creator<PhotoBean> CREATOR = new Creator<PhotoBean>() {
        @Override
        public PhotoBean createFromParcel(Parcel in) {
            return new PhotoBean(in);
        }

        @Override
        public PhotoBean[] newArray(int size) {
            return new PhotoBean[size];
        }
    };

    @Override
    public int compareTo(@NonNull Object o) {
        PhotoBean videoBean = (PhotoBean) o;
        String[] s = videoBean.date.split("-");
        String[] s2 = date.split("-");
        Calendar calendar = Calendar.getInstance();
        calendar.set(Integer.valueOf(s[0]), Integer.valueOf(s[1]), Integer.valueOf(s[2]));
        Calendar calendar2 = Calendar.getInstance();
        calendar2.set(Integer.valueOf(s2[0]), Integer.valueOf(s2[1]), Integer.valueOf(s2[2]));
        if (calendar.getTime().getTime() > calendar2.getTime().getTime())
            return 1;
        else if (calendar.getTime().getTime() < calendar2.getTime().getTime())
            return -1;
        else return 0;
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(date);
        dest.writeString(name);
        dest.writeString(resolution);
        dest.writeByte((byte) (isCheck ? 1 : 0));
        dest.writeInt(itemPosition);
    }
}
